Hausuebung FotoForum Tests
Current file: /home/estudydev/workspace/eStudy_svn/web/photogallery/classes/class.photofunctions.inc.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 0 / 0
100.00 %100.00%
100.00% 0 / 0
98.15 %98.15%
98.15% 106 / 108
 


       1                 : <?php                                                                                                       
       2                 : /*--------------------------------------------------------------------------+                               
       3                 : This file is part of eStudy.                                                                                
       4                 : photogallery/classes/class.photofunctions.inc.php                                                           
       5                 : - Modulgruppe:  Photogallery                                                                                
       6                 : - Beschreibung: Diverse Funktionen                                                                          
       7                 : - Version:      02/26/04                                                                                    
       8                 : - Autor(en):    Thomas Loreit <smg@newtron-game.com>                                                        
       9                 : +---------------------------------------------------------------------------+                               
      10                 : This program is free software; you can redistribute it and/or                                               
      11                 : modify it under the terms of the GNU General Public License                                                 
      12                 : as published by the Free Software Foundation; either version 2                                              
      13                 : of the License, or any later version.                                                                       
      14                 : +---------------------------------------------------------------------------+                               
      15                 : This program is distributed in the hope that it will be useful,                                             
      16                 : but WITHOUT ANY WARRANTY; without even the implied warranty of                                              
      17                 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                               
      18                 : GNU General Public License for more details.                                                                
      19                 : You should have received a copy of the GNU General Public License                                           
      20                 : along with this program; if not, write to the Free Software                                                 
      21                 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                 
      22                 : +--------------------------------------------------------------------------*/                               
      23                 : /**                                                                                                         
      24                 :  * Diverse Funktionen der Photogallery                                                                      
      25                 :  * @package eStudy.PhotoGallery                                                                             
      26                 :  * @author Thomas Loreit <smg@newtron-game.com>                                                             
      27                 :  * @version  1.3, 18.12.2005                                                                                
      28                 :  */                                                                                                         
      29                 : /**                                                                                                         
      30                 :  *    Diese Funktion mischt 2 Rechte aus der Datenbank                                                      
      31                 :  *                                                                                                          
      32                 :  *                                                                                                          
      33                 :  *                                                                                                          
      34                 :  */                                                                                                         
      35                 : function mergePhotoRights(&$to, &$from) {                                                                   
      36               1 :     if ($from->view == 1) $to->view = 1;                                                                    
      37               1 :     if ($from->upload == 1) $to->upload = 1;                                                                
      38               1 :     if ($from->edit == 1) $to->edit = 1;                                                                    
      39               1 :     if ($from->remove == 1) $to->remove = 1;                                                                
      40               1 :     if ($from->admin == 1) $to->admin = 1;                                                                  
      41               1 : }                                                                                                           
      42                 : /**                                                                                                         
      43                 :  *    Liefert true, wenn das angegebene Recht im übergebenen Objekt vorhanden ist, oder                    
      44                 :  *     der User ein Portaladmin, Student oder Dozent ist.                                                   
      45                 :  *                                                                                                          
      46                 :  *                                                                                                          
      47                 :  */                                                                                                         
      48                 : function testPhotoRight(&$rights, $rightname) {                                                             
      49               3 :     if ($_SESSION['usergroup'] == ADMIN) return true;                                                       
      50               3 :     if ($_SESSION['usergroup'] == DOZENT && $_SESSION['course'] != 0) return true;                          
      51               3 :         if ($rights) {                                                                                      
      52               3 :         if ($rights->admin) return true;                                                                    
      53               3 :         $result = 0;                                                                                        
      54               3 :         eval('$result=$rights->'.$rightname.';');                                                           
      55               3 :         return $result == 1;                                                                                
      56               1 :     } else return false;                                                                                    
      57                 : }                                                                                                           
      58                 : /**                                                                                                         
      59                 :  * Liefert die Rechte des Users in der Photogallery des aktuellen Kurses.<br/><br/>                         
      60                 :  * Die Funktion benutzt die Session um die User-ID und Kurs-ID zu bekommen.<br/><br/>                       
      61                 :  *                                                                                                          
      62                 :  *                                                                                                          
      63                 :  *                                                                                                          
      64                 :  * @access public                                                                                           
      65                 :  * @static                                                                                                  
      66                 :  * @return Objekt in der Form der photogallery_rights Tabelle.                                              
      67                 :  * Wenn die Funktion nichts zurückliefert wurden keine Rechte gefunden                                     
      68                 :  */                                                                                                         
      69                 : function getGalleryRights() {                                                                               
      70               2 :     global $settings, $db, $EZSQL_ERROR;                                                                    
      71               2 :     $safecourse = Data::toMysql($_SESSION['course']);                                                       
      72               2 :     $safeuser = Data::toMysql($_SESSION['userid']);                                                         
      73               2 :     if ($_SESSION['usergroup'] == SCHUELER || $_SESSION['usergroup'] == GAST){                              
      74               1 :         $globalrights = $db->get_row(                                                                       
      75                 :                                     "SELECT 1 as view,                                                      
      76                 :                                             0 as upload,                                                    
      77                 :                                             0 as edit,                                                      
      78                 :                                             0 as remove,                                                    
      79                 :                                             0 as admin                                                      
      80                 :                                       FROM photogallery_rights                                              
      81               1 :                                       WHERE course_id=".$safecourse."                                       
      82                 :                                       AND album_id='0'                                                      
      83                 :                                       AND usr_id='0' LIMIT 1"                                               
      84               1 :                                     );                                                                      
      85               1 :     }else{                                                                                                  
      86               2 :         $globalrights = $db->get_row(                                                                       
      87                 :                                     "SELECT *                                                               
      88                 :                                      FROM photogallery_rights                                               
      89               2 :                                      WHERE course_id=".$safecourse."                                        
      90                 :                                      AND album_id='0'                                                       
      91                 :                                      AND usr_id='0' LIMIT 1"                                                
      92               2 :                                     );                                                                      
      93                 :     }                                                                                                       
      94               2 :     $userrights = $db->get_row(                                                                             
      95                 :                                 "SELECT *                                                                   
      96                 :                                  FROM photogallery_rights                                                   
      97               2 :                                  WHERE course_id=".$safecourse."                                            
      98                 :                                  AND album_id='0'                                                           
      99               2 :                                  AND usr_id='".$safeuser."' LIMIT 1"                                        
     100               2 :                                 );                                                                          
     101               2 :     if (!$db->num_rows) {                                                                                   
     102               2 :         $globalrights = $db->get_row("SELECT 1 as view, 1 as upload, 1 as edit, 1 as remove, 0 as admin");  
     103               2 :     }                                                                                                       
     104               2 :     if ($globalrights) {                                                                                    
     105               2 :         if ($userrights) mergePhotoRights($globalrights, $userrights);                                      
     106               2 :         return $globalrights;                                                                               
     107               0 :     } else if ($userrights) return $userrights;                                                             
     108               0 : }                                                                                                           
     109                 : /**                                                                                                         
     110                 :  * Liefert die Rechte des Users in einem Album in der Photogallery des aktuellen Kurses.<br/><br/>          
     111                 :  * Die Funktion benutzt die Session um die User-ID und Kurs-ID zu bekommen.<br/><br/>                       
     112                 :  *                                                                                                          
     113                 :  *                                                                                                          
     114                 :  *                                                                                                          
     115                 :  * @access public                                                                                           
     116                 :  * @static                                                                                                  
     117                 :  * @return Objekt in der Form der photogallery_rights Tabelle.                                              
     118                 :  * Wenn die Funktion nichts zurückliefert wurden keine Rechte gefunden                                     
     119                 :  */                                                                                                         
     120                 : function getAlbumRights($albumID) {                                                                         
     121               3 :     global $settings, $db, $EZSQL_ERROR;                                                                    
     122               3 :     $safecourse = Data::toMysql($_SESSION['course']);                                                       
     123               3 :     $safeuser = Data::toMysql($_SESSION['userid']);                                                         
     124               3 :     $safealbum = Data::toMysql($albumID);                                                                   
     125               3 :     $globalrights = $db->get_row(                                                                           
     126                 :                                 "SELECT *                                                                   
     127                 :                                  FROM photogallery_rights                                                   
     128               3 :                                  WHERE course_id=".$safecourse."                                            
     129               3 :                                  AND album_id='$safealbum'                                                  
     130               3 :                                  AND usr_id='0' LIMIT 1"                                                    
     131               3 :                                 );                                                                          
     132               3 :     $userrights = $db->get_row(                                                                             
     133                 :                                 "SELECT *                                                                   
     134                 :                                  FROM photogallery_rights                                                   
     135               3 :                                  WHERE course_id=".$safecourse."                                            
     136               3 :                                  AND album_id='$safealbum'                                                  
     137               3 :                                  AND usr_id='".$safeuser."' LIMIT 1"                                        
     138               3 :                                 );                                                                          
     139               3 :     if ($globalrights) {                                                                                    
     140               3 :         if ($userrights) mergePhotoRights($globalrights, $userrights);                                      
     141               3 :         return $globalrights;                                                                               
     142               2 :     } else if ($userrights) return $userrights;                                                             
     143               2 : }                                                                                                           
     144                 : function echoRightsSelectors($prefix, $photoView, $photoVpload, $photoEdit, $photoDelete, $photoAdmin) {    
     145               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_view' ";  
     146               1 :     echo $photoView == true ? 'checked=\'checked\'' : '';                                                   
     147               1 :     echo "/></td>";                                                                                         
     148               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_upload' ";
     149               1 :     echo $photoUpload == true ? 'checked=\'checked\'' : '';                                                 
     150               1 :     echo "/></td>";                                                                                         
     151               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_edit' ";  
     152               1 :     echo $photoEdit == true ? 'checked=\'checked\'' : '';                                                   
     153               1 :     echo "/></td>";                                                                                         
     154               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_delete' ";
     155               1 :     echo $photoDelete == true ? 'checked=\'checked\'' : '';                                                 
     156               1 :     echo "/></td>";                                                                                         
     157               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_admin' "; 
     158               1 :     echo $photoAdmin == true ? 'checked=\'checked\'' : '';                                                  
     159               1 :     echo "/></td>";                                                                                         
     160               1 : }                                                                                                           
     161                 : function echoGalleryRightsSelectors($prefix, $photoUpload, $photoEdit, $photoRemove) {                      
     162               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_upload' ";
     163               1 :     echo $photoUpload == true ? 'checked=\'checked\'' : '';                                                 
     164               1 :     echo "/></td>";                                                                                         
     165               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_edit' ";  
     166               1 :     echo $photoEdit == true ? 'checked=\'checked\'' : '';                                                   
     167               1 :     echo "/></td>";                                                                                         
     168               1 :     echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_remove' ";
     169               1 :     echo $photoRemove == true ? 'checked=\'checked\'' : '';                                                 
     170               1 :     echo "/></td>";                                                                                         
     171               1 : }                                                                                                           
     172                 : /**                                                                                                         
     173                 :  * Diese funktion listet alle User in Form von option Tags auf                                              
     174                 :  *                                                                                                          
     175                 :  * @access public                                                                                           
     176                 :  * @static                                                                                                  
     177                 :  */                                                                                                         
     178                 : function echoRightsUserlist($condition) {                                                                   
     179               1 :     global $db;                                                                                             
     180               1 :     $course = "";                                                                                           
     181               1 :     if ($_SESSION['course'] != 0) {                                                                         
     182               1 :         $course = "AND user.ID IN( SELECT userID FROM user_course WHERE courseID='{$_SESSION['course']}')"; 
     183               1 :     }                                                                                                       
     184               1 :     $query = "SELECT ID, Vorname, Nachname, Invisible, Usergroup FROM user WHERE user.ID > 0 $course        
     185               1 :              AND user.Invisible=0 $condition";                                                              
     186               1 :     $query.= " ORDER BY user.Nachname, user.Vorname";                                                       
     187               1 :     $users = $db->get_results($query);                                                                      
     188               1 :     if (count($users) > 0) {                                                                                
     189               1 :         $i = 0;                                                                                             
     190               1 :         foreach($users as $user) {                                                                          
     191               1 :             echo "<option ";                                                                                
     192               1 :             if ($user->Invisible == 1) echo "style='font-style:italic'";                                    
     193               1 :             echo " value='".$user->ID."' ";                                                                 
     194               1 :             echo ">";                                                                                       
     195               1 :             echo Data::toHTML("$user->Nachname, $user->Vorname", false);                                    
     196               1 :             echo "</option>\n";                                                                             
     197               1 :             $i++;                                                                                           
     198               1 :         }                                                                                                   
     199               1 :         return true;                                                                                        
     200               1 :     } else return false;                                                                                    
     201                 : }                                                                                                           
     202                 : /**                                                                                                         
     203                 :  *    Verwendet die Funktion testPhotoRight, aber holt vorher die Rechte für den aktuellen Kurs            
     204                 :  *     aus der Datenbank                                                                                    
     205                 :  */                                                                                                         
     206                 : function getGalleryRight($rightname) {                                                                      
     207               1 :     $rights = getGalleryRights();                                                                           
     208               1 :     return testPhotoRight($rights, $rightname);                                                             
     209                 : }                                                                                                           
     210                 : /**                                                                                                         
     211                 :  *    Verwendet die Funktion testPhotoRight, aber holt vorher die Rechte für den aktuellen Kurs und        
     212                 :  *     des angegebenen Albums aus der Datenbank                                                             
     213                 :  */                                                                                                         
     214                 : function getAlbumRight($rightname, $albumid) {                                                              
     215               1 :     $rights = getAlbumRights($albumid);                                                                     
     216               1 :     return testPhotoRight($rights, $rightname);                                                             
     217                 : }                                                                                                           

Generated by PHPUnit 3.2.21 and Xdebug 2.0.3 at Sun Dec 27 23:47:06 CET 2009.